
layui.use('table',function(){


     $ = layui.jquery;
    var table = layui.table;



    //用户列表
    var tableIns=table.render({

        elem: '#carParkInfo',
        url : '/sharepark/platform/carPark',
        page : true,
        height : "full-100",
        limits : [10,20,30,40],
        limit : 10,
        id : "carParkInfo",
        text:{none:'暂无相关数据'},
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
            {field: 'cNumber', title: '车位号', sort:true, align:"center"},
            {field: 'uName', title: '出租方姓名', align:'center',templet: '<div>{{d.userInfo.uName}}</div>' },
            {field: 'uTel', title: '出租方电话', align:'center',templet: '<div>{{d.userInfo.uTel}}</div>'},
            {field: 'comName', title:'小区名字', align:'center',templet: '<div>{{d.community.comName}}</div>'},
            {field: 'cStatus', title: '审核状态', sort:true, align:'center'},
            {field: 'cState', title: '租赁状态', sort:true, align:'center'},
            {title: '操作', minWidth:175, templet:'#carparkListBar',fixed:"right",align:"center"}
        ]]
    });

    //监听行工具事件
    table.on('tool(carParkInfo)', function(obj){
        var data = obj.data;
        // console.log(obj)
        if(obj.event === 'edit'){
            if (data.cStatus=="通过" || data.cStatus=="未通过") {
                layer.alert("选中的数据有误，请重新选择");
                return;
            }
            layer.confirm('确定审核通过吗？', function(index){
                var param = data.id;
                var phone = data.userInfo.uTel;


                $.post("/sharepark/platform/check","param="+param+"&phone="+phone,function (res) {
                    layer.msg(res.msg);
                    if (res.msg ==='审核通过'){
                        tableIns.reload();
                    }
                })
            });
        }


        if (obj.event ==='remove'){
            if (data.cState ==='已租'){

                layer.alert("该车位已出租，不能下架", {icon: 2});
            }else if (data.cState ==='下架'){
                layer.alert("该车位已下架", {icon: 2});
            }else{
                layer.confirm('确定下架该车位吗？',{icon:3},function (index) {
                    // layer.Close(index);
                    var param = data.id;

                    $.post("/sharepark/platform/removeCarPark","id="+param,function (res) {
                        layer.msg(res.msg);
                        if (res.msg ==='已下架'){
                            tableIns.reload();
                        }
                    })
                });
            }
        }
    });


    //搜索
    $(".search_btn").on("click",function(){

        tableIns.reload({
            where: {
                "cNumber": $('#cNumber').val(),
                "userInfo.uName":$('#userName').val(),
                "cStatus":$('#cStatus').val(),
                "cState":$('#cState').val()

            }
            ,page: {
                curr: 1 //重新从第 1 页开始
            }
        });

    });




})
